package com.yw.swagger.controller;

import com.yw.swagger.customNote.fyh;
import com.yw.swagger.customNote.qw;
import com.yw.swagger.model.SysBpsUsers;
import com.yw.swagger.service.SysBpsUsersService;
import com.yw.swagger.tool.AjaxResult;
import com.yw.swagger.tool.Utils.ServletUtils;
import com.yw.swagger.tool.Utils.StringUtils;
import com.yw.swagger.tool.controller.BaseController;
import io.swagger.annotations.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;

/**
 * Created by 14267 on 2019/10/24
 */
@Controller
@Api(tags="用户登录接口")
@RequestMapping("/sys_user")
public class SysBpsUserLoginController extends BaseController {

    @Autowired
    private SysBpsUsersService sysBpsUsersService;

    @qw
    @ApiOperation(value = "用户登录",notes = "用户登录")
    @ApiResponses({@ApiResponse(code = 200,message = "成功"),@ApiResponse(code = 500,message = "error")})
    @ApiImplicitParams({@ApiImplicitParam(name="username",value="用户账号",required = true,dataType = "String"),@ApiImplicitParam(name="password",value="用户密码")})
    @PostMapping("/login")
    @ResponseBody
    public AjaxResult login(HttpServletRequest request,String username, String password){
        if(StringUtils.isNull(username)||StringUtils.isNull(password)){
            return AjaxResult.error("用户名或密码为空");
        }

        return sysBpsUsersService.userLogin(username,password,request);
    }


    @fyh
    @ApiOperation(value = "获取登录用户信息",notes = "获取登录用户信息")
    @ApiResponses({@ApiResponse(code = 200,message = "成功"),@ApiResponse(code = 500,message = "error")})
    @ApiImplicitParam(name="author",value="权限码",required = true)
    @PostMapping("/loginMessage")
    @ResponseBody
    public AjaxResult loginMessage(){
        String userAccout=(String) ServletUtils.getSession().getAttribute("name");
        if(userAccout==null){
            return AjaxResult.error();
        }
        //查询用户详情
        SysBpsUsers user=sysBpsUsersService.selectSysBpsUsers(userAccout);
        return AjaxResult.success(user);
    }
}
